package com.alan.product.issue.metaspace;

import com.alan.product.issue.content.BusinessService;
import com.alan.product.issue.content.BusinessServiceImpl;
import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;

/**
 * @author tangtong
 * @date 2021/7/7
 */
public class MetaspaceOomTest {
    public static void main(String[] args) {
        // -XX:MetaspaceSize=10m -XX:MaxMetaspaceSize=10m
        long count = 0L;
        while (true) {
            Enhancer enhancer = new Enhancer();
            enhancer.setSuperclass(BusinessServiceImpl.class);
            enhancer.setUseCache(false);
            enhancer.setCallback((MethodInterceptor) (o, method, objects, methodProxy) -> {
                System.out.println("before hello");
                return methodProxy.invokeSuper(o, objects);
            });

            BusinessService businessService = (BusinessService) enhancer.create();
            businessService.hello("alan");

            System.out.println(++count);
        }
    }
}
